package com.hospital.demo.controller.jiajinpeng;

import com.hospital.demo.model.jiajinpeng.OutHospital;
import com.hospital.demo.service.jiajinpeng.OutHospitalSer;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/out")
@Api(tags={"入院"})
public class OutHospitalCon {

    @Autowired
    private OutHospitalSer outHospitalSer;

    @ApiOperation(value = "获取全部入院信息", notes = "")
    @GetMapping("/findAll")
    private ResultVO findAllout() {
        return ResultUtils.success(outHospitalSer.selectAlllist());
    }

    @ApiOperation(value = "根据患者id查询", notes = "")
    @GetMapping("/findAllname")
    private ResultVO findbyout(@RequestParam(name = "pname",defaultValue = "null")String pname) {
        return ResultUtils.success(outHospitalSer.selectByname(pname));
    }

    @ApiOperation(value = "插入出院信息", notes = "")
    @PostMapping("/insertout")
    protected ResultVO insert(OutHospital outHospital) {
        return ResultUtils.success(outHospitalSer.insert(outHospital));
    }

    @InitBinder
    private void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
}
